import asyncio
import json
import websockets
import time
import numpy as np

from fileStream import FileStream

# 从文件读取通道数据，模拟数据采集客户端
async def virtualDataClient():
    path = "./data/new_data.txt"
    fileStream = FileStream(path)
    print('connecting ws://localhost:8765/data ......')
    async with websockets.connect("ws://localhost:8765/data") as websocket:
        print('connect ws://localhost:8765/data successfully')
        for channel in fileStream:
            data = {'personId': 0, 'channel': channel.tolist()}
            str = json.dumps(data)
            await websocket.send(str)

# asyncio.run(virtualDataClient())

# data = np.array([1,2])
# print(data)
# print(data.tolist())